package com.learnyou.server.xingzuo.dto.resultDTO;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

/**
 * @author heweifeng
 * @Description:
 * @date 2022/10/14 15:43
 */
@Data
public class PurchaseOverviewDTO {


    @ApiModelProperty(value = "机构id")
    private String id;

    @ApiModelProperty(value = "到期时间")
    private Date expiredAt;

    @ApiModelProperty(value = "购买时间")
    private Date purchaseAt;

    @ApiModelProperty(value = "距离到期日期剩余天数")
    private Integer expireDays;

    @ApiModelProperty("已经服务天数")
    private Integer serviceDays;

    /**
     * 统计天数
     */
    public void statDays() {
        Long eDays = DateUtil.between(new Date(), expiredAt, DateUnit.DAY);
        Long sDays = DateUtil.between(purchaseAt, new Date(), DateUnit.DAY);
        setExpireDays(eDays.intValue());
        setServiceDays(sDays.intValue());
    }
}
